<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="edge" />
<link rel="shortcut icon" href="${root}/asset/example/favicon.ico" />
<title>商品管理</title>
<link href="${root}/asset/themes/insdep/easyui.css" rel="stylesheet" type="text/css">
<link href="${root}/asset/themes/insdep/easyui_animation.css" rel="stylesheet" type="text/css">
<link href="${root}/asset/themes/insdep/easyui_plus.css" rel="stylesheet" type="text/css">
<link href="${root}/asset/themes/insdep/insdep_theme_default.css" rel="stylesheet" type="text/css">
<link href="${root}/asset/themes/insdep/icon.css" rel="stylesheet" type="text/css">
<link href="${root}/asset/plugin/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<script src="${root}/asset/jquery.min.js"></script>
<script src="${root}/asset/jquery.easyui.min.js"></script>
<script src="${root}/asset/themes/insdep/jquery.insdep-extend.min.js"></script>
<style type="text/css">
.layout-panel-west {
    border-right: 1px solid #c5c5c5;
}
</style>
</head>
<body>
    <table id="${class_ss}_datagrid" style="height: 500px;">
        <thead>
            <tr>
                <th data-options="field:'ck',checkbox:true"></th>
                <#list datagrid_columns as c>
                <th data-options="${c}"></th>
                </#list>
                <#if (operationCount>0)>
                <th data-options="field:'button',width:${operationCount*90},fixed:true,align:'center',formatter:App.${class_ss}.datagrid_buttons">操作</th>
                </#if>
            </tr>
        </thead>
    </table>
    <#if toolbar>
    <div id="${class_ss}_toolbar" style="padding:2px 5px;">
        <#if save>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="${class_ss}_save_btn">新增</a>
        </#if>
        <#if deleteByIds>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" id="${class_ss}_delete_btn">删除选中</a>
        </#if>
        <span class="datagrid-btn-separator" style="vertical-align: middle; height: 25px;display:inline-block;float:none"></span>
        <#if (search_html?size> 0)>
        <#list search_html as sh>
        ${sh}
        </#list>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="${class_ss}_search_btn">搜索</a>
        </#if>
    </div>
    </#if>
    <#if save>
    <div id="${class_ss}_save_dlg" class="easyui-dialog" title="新增" data-options="iconCls:'icon-add',cls:'dialog',modal:true,closed:true,buttons:'#${class_ss}_save_buttons'" style="width:400px;height:${save_height}px;">
        <div style="padding:0px 60px 0px 60px">
            <form id="${class_ss}_save_form" method="post">
                <table style="border-spacing:10px;">
                    <#list save_html as sh>
                    ${sh}
                    </#list>
                </table>
            </form>
        </div>
    </div>
    <div id="${class_ss}_save_buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton button-default" id="${class_ss}_save_confirm">确定</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" id="${class_ss}_save_cancel">取消</a>
    </div>
    </#if>
    <#if update>
    <div id="${class_ss}_update_dlg" class="easyui-dialog" title="修改" data-options="iconCls:'icon-edit',cls:'dialog',modal:true,closed:true,buttons:'#${class_ss}_update_buttons'" style="width:400px;height:${update_height}px;">
        <div style="padding:0px 60px 0px 60px">
            <form id="${class_ss}_update_form" method="post">
                <table style="border-spacing:10px;">
                    <#list update_html as sh>
                    ${sh}
                    </#list>
                </table>
            </form>
        </div>
    </div>
    <div id="${class_ss}_update_buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton button-default" id="${class_ss}_update_confirm">确定</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" id="${class_ss}_update_cancel">取消</a>
    </div>
    </#if>
    <#list middleProperties as m>
    <div id="${class_ss}_modify_${m.op_ss}_dlg" class="easyui-dialog" title="编辑${m.title}" data-options="iconCls:'icon-edit',cls:'dialog',modal:true,closed:true,buttons:'#${class_ss}_modify_${m.op_ss}_buttons'" style="width:400px;height:180px;">
        <div style="padding:0px 60px 0px 60px">
            <form id="${class_ss}_modify_${m.op_ss}_form" method="post">
                <input type="hidden" name="${m.ownVar}">
                <table style="border-spacing:10px;">
                    <tr>
                        <td><select name="${m.oppositeVar}s" id="${class_ss}_modify_${m.op_ss}_combotree" class="easyui-combotree" data-options="editable:false,method:'get',multiple:true,url:'${root}/${m.op_ss}/findAllTree',panelHeight:'auto'" style="width:250px;"></select></td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <div id="${class_ss}_modify_${m.op_ss}_buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton button-default" id="${class_ss}_modify_${m.op_ss}_confirm">确定</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" id="${class_ss}_modify_${m.op_ss}_cancel">取消</a>
    </div>
    </#list>
    <script>
$.xpost = function(formid, url){
    return $.ajax(url, { method:"post", data:new FormData(document.getElementById(formid)), contentType:false, processData:null});
};
var App = window.App || {};
$(function() {
    ${remote_begin}
        <#list local_sources as ds>
        var ${ds.var} = ${ds.value};
        </#list>
        App.${class_ss} = (function(){
        <#list datagrid_formatters as fp>
            var ${fp.funcName} = function (value, row, index) {
                ${fp.funcBody}
            }
        </#list>
            return {
                ${public_methods}<#if (public_methods?length>0)&&(operationCount>0)>,</#if><#if (operationCount>0)>${operationHtml}</#if>
            };
        }());

        <#if (search_html?size> 0)>// 条件查询逻辑--------begin
        $("#${class_ss}_search_btn").click(function(){
            var param={};
            var all = $("#${class_ss}_toolbar [name]");
            for(var i = 0; i < all.length; i++){
                var dom = all[i];
                if(dom.value == ""){ // 如果没有值，不必作为参数
                    continue;
                }
                if(param[dom.name]===undefined){
                    param[dom.name]=[];
                }
                param[dom.name].push(dom.value);
            }
            // jquery直接发送数组类型参数，不能与springmvc很好配合，转换为逗号分隔的字符串
            for(var key in param){
                param[key] = param[key].join(",");
            }
            $("#${class_ss}_datagrid").datagrid("load", param);
        });
        <#list search_func as sf>
        ${sf}
        </#list>
        // 条件查询逻辑--------end
        </#if>

        <#if save>// 新增逻辑--------begin
        $("#${class_ss}_save_btn").click(function(){
            $("#${class_ss}_save_dlg").dialog("open");
        });
        $("#${class_ss}_save_confirm").click(function(){
            $.xpost("${class_ss}_save_form", "${root}/${class_ss}/save").done(function(){
                $('#${class_ss}_datagrid').datagrid("load");
                $("#${class_ss}_save_dlg").dialog("close");
            });
        });
        $("#${class_ss}_save_cancel").click(function(){
            $("#${class_ss}_save_dlg").dialog("close");
        });
        <#list save_func as sf>
        ${sf}
        </#list>
        // 新增逻辑--------end
        </#if>

        <#if update>// 修改逻辑--------begin
        $("#${class_ss}_update_confirm").click(function(){
            $.xpost("${class_ss}_update_form", "${root}/${class_ss}/update").done(function(){
                $('#${class_ss}_datagrid').datagrid("load");
                $("#${class_ss}_update_dlg").dialog("close");
            });
        });
        $("#${class_ss}_update_cancel").click(function(){
            $("#${class_ss}_update_dlg").dialog("close");
        });
        <#list update_func as sf>
        ${sf}
        </#list>
        // 修改逻辑--------end
        </#if>

        <#if deleteByIds>// 删除选中逻辑--------begin
        $("#${class_ss}_delete_btn").click(function(){
            var rows = $('#${class_ss}_datagrid').datagrid("getSelections");
            if(rows.length==0){
                $.messager.alert("删除", "请选中要删除的行!");
                return;
            }
            $.messager.confirm("删除", "确定要删除吗?", function(r){
                if(r) {
                    var ids = rows.map(r=>r.${id_property}).join(",");
                    $.get("${root}/${class_ss}/deleteByIds", {${id_property}:ids}).done(function(){
                        $('#${class_ss}_datagrid').datagrid("load");
                    });
                }
            });
        });
        // 删除选中逻辑--------end
        </#if>

        // 编辑一对多关系--------begin
        <#list middleProperties as m>
        $("#${class_ss}_modify_${m.op_ss}_confirm").click(function(){
            $.xpost("${class_ss}_modify_${m.op_ss}_form", "${root}/${class_ss}/modify${m.op_s}s").done(function(){
                $("#${class_ss}_modify_${m.op_ss}_dlg").dialog("close");
            });
        });
        $("#${class_ss}_modify_${m.op_ss}_cancel").click(function(){
            $("#${class_ss}_modify_${m.op_ss}_dlg").dialog("close");
        });
        </#list>
        // 编辑一对多关系--------end

        $('#${class_ss}_datagrid').datagrid({
            cls : "theme-datagrid",
            pagination : true,
            fitColumns : true,
            fit:true,
            method:"get",
            <#if toolbar>
            toolbar: "#${class_ss}_toolbar",
            </#if>
            url : '${root}/${class_ss}/datagrid',
            onLoadSuccess : function() {
                <#list middleProperties as m>
                $(".button-edit.oper-${m.op_ss}").linkbutton({
                    iconCls : 'icon-edit'
                }).click(function(){
                    var id = $(this).data("id");
                    $("#${class_ss}_modify_${m.op_ss}_form [name=${m.ownVar}]").val(id);
                    $.get("${root}/${class_ss}/get${m.op_s}s", {${m.ownVar}:id}).done(function(json){
                        $("#${class_ss}_modify_${m.op_ss}_combotree").combotree("setValues", json);
                        $("#${class_ss}_modify_${m.op_ss}_dlg").dialog("open");
                    });
                });
                </#list>
                <#if update>
                $('.button-edit.oper').linkbutton({
                    iconCls : 'icon-edit'
                }).click(function(){
                    var id = $(this).data("id");
                    $.get("${root}/${class_ss}/findById", {${id_property}:id}).done(function(json){
                        $("#${class_ss}_update_form").form("load", json);
                        $("#${class_ss}_update_dlg").dialog("open");
                    });
                });
                </#if>
                <#if deleteById>
                $('.button-delete.oper').linkbutton({
                    iconCls : 'icon-remove'
                }).click(function() {
                    var id = $(this).data("id");
                    $.messager.confirm("删除", "确定要删除吗?", function(r){
                        if(r) {
                            $.get("${root}/${class_ss}/deleteById", {${id_property}:id}).done(function(){
                                $('#${class_ss}_datagrid').datagrid("load");
                            });
                        }
                    });
                });
                </#if>
            }
        });
    ${remote_end}
});
    </script>
</body>
</html>